// sw.js

const CACHE_NAME = "my-cache-v1";
const urlsToCache = [
  "/",
  "/index.html",
  "/styles.css",
  "/script.js",
  "/images/logo.png",
  "/images/background.jpg",
  "/images/icon.png",
  "/manifest.json",
  "/service-worker.js",
  "/sw.js",
];

self.addEventListener("install", (event) => {
  event.waitUntil(
    caches.open(CACHE_NAME).then((cache) => {
      console.log("Opened cache", cache);
      //   return cache.addAll(urlsToCache);
      // 返回空的
      return cache.addAll([]);
    })
  );
});

self.addEventListener("fetch", (event) => {
  event.respondWith(
    caches.match(event.request).then((response) => {
      return response || fetch(event.request);
    })
  );
});
